/*
 * Eugen Stoian <stoian.e@gmail.com> 2010
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "Point.h"
#include <cmath>
#include <cfloat>
#include <Real.h>
Point::Point(double x, double y, double z, double w) {
    _data[0]=x;
    _data[1]=y;
    _data[2]=z;
    _data[3]=w;
}

Point::Point(const Point& p) {
    _data[0]=p._data[0];
    _data[1]=p._data[1];
    _data[2]=p._data[2];
    _data[3]=p._data[3];
    _parameterValue = p._parameterValue;
}

Point& Point::operator=(const Point& p) {
    if(this!=&p){
        _data[0]=p._data[0];
        _data[1]=p._data[1];
        _data[2]=p._data[2];
        _data[3]=p._data[3];
        _parameterValue = p._parameterValue;
    }
    return *this;

}

bool Point::operator==(const Point& point) const{
    if((w()!=0.0)&&(point.w()!=0.0))
        return (x()/w()==point.x()/point.w())&&(y()/w()==point.y()/point.w())&&(z()/w()==point.z()/point.w());
    if((w()==0.0)&&(point.w()==0.0))
        return (x()==point.x())&&(y()==point.y())&&(z()==point.z());
    return false;
}

bool Point::operator!=(const Point& point) const{
    return !(*this==point);
}
bool Point::isValid() const {
    return (_data[0]==_data[0]) && (_data[1]==_data[1]) && (_data[2]==_data[2])&& (_data[3]==_data[3]);

}

bool Point::isFinite() const {
    return Real(_data[0]).isFinite() && Real(_data[1]).isFinite() && Real(_data[2]).isFinite() &&(_data[3]!=0.0);
}

double Point::parameterValue() const {
    return _parameterValue;
}
void Point::setParameterValue(double t){
    _parameterValue = t;
}
